package xin.huangyan.accessibilityremote;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.text.TextUtils;
import android.util.Log;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.Toast;

import org.json.JSONException;
import org.json.JSONObject;

public class WeixinDialogActivity extends Activity {
    private TextView comfirm_textview;
    private TextView btnReply;
    private TextView tipTextView;
    private TextView tipTitle;
    private EditText editTextReply;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_weixin_dialog_activity);
        this.setFinishOnTouchOutside(false);//设置窗口周围触摸不消失
        getWindow().setDimAmount(0.6f);//设置窗口周围透明
        initView();
    }
    private void initView() {
        editTextReply = (EditText) this.findViewById(R.id.editTextReply);
        comfirm_textview = (TextView) this.findViewById(R.id.comfirm_textview);
        btnReply = (TextView) this.findViewById(R.id.btnReply);
        tipTextView = (TextView) this.findViewById(R.id.tipTextView);
        tipTitle = (TextView) this.findViewById(R.id.tipTitle);
        comfirm_textview.setClickable(true);
        comfirm_textview.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View paramView) {
                finish();
            }
        });
        btnReply.setClickable(true);
        btnReply.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View paramView) {
//                Toast.makeText(WeixinDialogActivity.this, "回复："+editTextReply.getText().toString(),
//                        Toast.LENGTH_SHORT).show();
                JSONObject sendObj = new JSONObject();
                try {
                    sendObj.put("command", "send");
                    sendObj.put("msg", editTextReply.getText().toString());
                } catch (JSONException e) {
                    e.printStackTrace();
                }
                new MainActivity.ConnectionThread(sendObj.toString()).start();
                finish();
            }
        });

        Intent intent = getIntent();
        if (intent != null) {
            String msg = intent.getStringExtra("msg");
            if (!TextUtils.isEmpty(msg)) {
                if (msg.contains(":")) {
                    String[] msgs = msg.split(":");
                    tipTitle.setText(msgs[0]+"发来的微信消息");
                    tipTextView.setText(msgs[1]);
                }else{
                    tipTextView.setText(msg);
                }
            }
        }
    }
}